package com.lap.framework.junit.domain.generator;

import com.lap.framework.junit.domain.ClassInfo;
import com.lap.framework.junit.domain.FileInfo;
import com.lap.framework.junit.shared.tool.CodeType;
import com.lap.framework.junit.shared.tool.ProjectUtil;
import java.util.Collections;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JavaCodeGenerator implements CodeGenerator {

  @Override
  public List<FileInfo> generate(ClassInfo classInfo) {
    if (classInfo == null) {
      return Collections.emptyList();
    }

    String path = ProjectUtil.getTestPath(classInfo.getPackageName());
    log.info("文件路径::>{}", path);
    String fileName = classInfo.getFileName() + "Test.java";
    TestFileBuilder builder = new TestFileBuilder.Default();
    TestFileDirector director = new TestFileDirector(builder);
    String content = director.construct(classInfo);
    return List.of(FileInfo.of(path, fileName, content));
  }

  @Override
  public CodeType getType() {
    return CodeType.JAVA;
  }
}
